Encoder.h
/*************************************************
* Work with incremental Encoders (Functions require interrupts from a Timer/Counter)
*************************************************/
#ifndef _ENCODER_H_
#define _ENCODER_H_
#include <xc.h>
#include "main.h"
#include "PIN_avr.h"
#include "UART_avr.h"
/* Clockwise rotation = "right"
* Counterclockwise rotation = "left"
* byte values - to be defined
*/
typedef enum
{
R_TICK = 0b01,
L_TICK = 0b10,
NO_TICK = 0b11
} enc_direction;
typedef struct
{
pin_t pin1;
pin_t pin2;
my_bool pin1_state;
my_bool pin2_state; // current state of a pin (needed??)
my_bool tick_registered;
enc_direction dir; // a byte to save state of encoder pins: 0b0000 00xx
uint8_t ticks_RIGHT; // Amount of ticks to process right
uint8_t ticks_LEFT; // Amount of ticks to process left
} encoder_t;
/**************************** FUNCTION PROTOTYPES ****************************/
void init_encoder(encoder_t* Encoder, pin_t _pin1, pin_t _pin2);
void update_enc_state(encoder_t* Encoder);
void print_enc_state(encoder_t* Encoder);
#endif // _ENCODER_H_